import request from '@/request/request'

// 合同管理API
export const contractApi = {
  // 分页查询合同列表
  getContractPage: (data) => {
    return request({
      url: '/contract/page',
      method: 'post',
      data
    })
  },

  // 根据ID查询合同详情
  getContractById: (id) => {
    return request({
      url: `/contract/${id}`,
      method: 'get'
    })
  },

  // 新增合同
  addContract: (data) => {
    return request({
      url: '/contract',
      method: 'post',
      data
    })
  },

  // 更新合同
  updateContract: (id, data) => {
    return request({
      url: `/contract/${id}`,
      method: 'put',
      data
    })
  },

  // 删除合同
  deleteContract: (id) => {
    return request({
      url: `/contract/${id}`,
      method: 'delete'
    })
  },

  // 提交审批
  submitForApproval: (id) => {
    return request({
      url: `/contract/${id}/submit`,
      method: 'post'
    })
  },

  // 审批通过
  approveContract: (id) => {
    return request({
      url: `/contract/${id}/approve`,
      method: 'post'
    })
  },

  // 审批拒绝
  rejectContract: (id, reason) => {
    return request({
      url: `/contract/${id}/reject`,
      method: 'post',
      params: { reason }
    })
  },

  // 完成合同
  completeContract: (id) => {
    return request({
      url: `/contract/${id}/complete`,
      method: 'post'
    })
  },

  // 终止合同
  terminateContract: (id, reason) => {
    return request({
      url: `/contract/${id}/terminate`,
      method: 'post',
      params: { reason }
    })
  },

  // 获取合同状态列表
  getContractStatusList: () => {
    return request({
      url: '/contract/status/list',
      method: 'get'
    })
  },

  // 获取合同类型列表
  getContractTypeList: () => {
    return request({
      url: '/contract/type/list',
      method: 'get'
    })
  },

  // ==================== 合同模板相关API ====================

  // 获取合同模板列表
  getContractTemplateList: (templateType) => {
    return request({
      url: '/contract/template/list',
      method: 'get',
      params: { templateType }
    })
  },

  // 分页查询合同模板
  getContractTemplatePage: (data) => {
    return request({
      url: '/contract/template/page',
      method: 'post',
      data
    })
  },

  // 根据ID获取合同模板详情
  getContractTemplateById: (id) => {
    return request({
      url: `/contract/template/${id}`,
      method: 'get'
    })
  },

  // 新增合同模板
  addContractTemplate: (data) => {
    return request({
      url: '/contract/template',
      method: 'post',
      data
    })
  },

  // 更新合同模板
  updateContractTemplate: (id, data) => {
    return request({
      url: `/contract/template/${id}`,
      method: 'put',
      data
    })
  },

  // 删除合同模板
  deleteContractTemplate: (id) => {
    return request({
      url: `/contract/template/${id}`,
      method: 'delete'
    })
  },

  // 根据模板创建合同
  createContractFromTemplate: (templateId, data) => {
    return request({
      url: `/contract/create-from-template/${templateId}`,
      method: 'post',
      data
    })
  }
}
